package com.example.yin.service.impl;

import com.example.yin.dao.ArticleMapper;
import com.example.yin.dao.SubscribeMapper;
import com.example.yin.domain.Article;
import com.example.yin.domain.Subscribe;
import com.example.yin.service.ArticleService;
import com.example.yin.vo.ArticleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @description
 * @createDate 2023/6/26
 */

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    ArticleMapper articleMapper;

    @Autowired
    SubscribeMapper subscribeMapper;

    @Override
    public boolean add(Article article) {
        int insert = articleMapper.insert(article);
        if (insert > 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(Integer article_id) {
        int delete = articleMapper.delete(article_id);
        if (delete > 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean update(Article article) {
        int i = articleMapper.updateByPrimaryKey(article);
        if (i > 0){
            return true;
        }
        return false;
    }

    @Override
    public Article getDetail(Integer article_id) {
        Article article = articleMapper.selectByPrimaryKey(article_id);
        if (article != null){
            return article;
        }
        return null;
    }


    @Override
    public boolean updateArticlePic(Article article) {

        return articleMapper.updateArticlePic(article)>0?true:false;
    }

    @Override
    public List<Article> getList(Article article) {
        List<Article> list = articleMapper.getList(article);
        if (list != null){
            return list;
        }
        return null;
    }

    @Override
    public List<ArticleVO> getListVO(ArticleVO articleVO) {
        return articleMapper.getListVO(articleVO);
    }

    @Override
    public boolean isExist(Integer user_id, Integer sub_user_id) {
        return subscribeMapper.isExist(user_id,sub_user_id);
    }

    @Override
    public boolean insertIntoSubscribe(Integer user_id, Integer sub_user_id) {
        return subscribeMapper.insert(user_id,sub_user_id) > 0 ? true:false;
    }

    @Override
    public boolean deleteSubscribe(Integer user_id, Integer sub_user_id) {
        return subscribeMapper.deleteByPrimaryKey(user_id,sub_user_id) > 0 ? true:false;
    }


    public List<Article> getSubArticle(int user_id){
        List<Article> list =articleMapper.getSubArticle(user_id);
        if (list != null){
            return list;
        }
        return null;
    }
    @Override
    public boolean subscribe(Subscribe subscribe){
        return articleMapper.subscribeUser(subscribe)>0?true:false;
    }
}
